﻿using IT_RoadBlock.Entities;
using System.Data.Entity;

namespace IT_RoadBlock.DataContexts
{
	public class FyDbContext : DbContext
	{
		public FyDbContext() : base("FyDbContext")
		{
		}

		public DbSet<TProjectInfo> TProjectInfoDbSet { get; set; }
		public DbSet<TProjectInjectionInfo> InjectionDbSet { get; set; }

		//1.安装System.Data.SQLite.EF6 （安装时会自动安装对应的EntityFramework版本) 
		//2.安装System.Data.SQLite (虽然安装了System.Data.SQLite.EF6  但里面却没有集成System.Data.SQLite 在配置数据库连接时 有个属性providerName需要设置为"System.Data.SQLite.EF6" 
		//3.假设没有安装System.Data.SQLite，一致提示错误如下 但你把对应的providerName换成System.Data.SQLite还是System.Data.SQLite.EF6都无济于事，通过反编译工具查看System.Data.SQLite.EF6 就知道没有对应SqliteConnection 意味着连接不了Sqlite
		/*	System.InvalidOperationException:“The Entity Framework provider type 'System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6' 
			registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SQLite.EF6' could not be loaded. 
			Make sure that the assembly-qualified name is used and that the assembly is available to the running application.
			See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.”*/

		//4. 如果在报错No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SQLite'. 再检查配置文件中是否存在
		//<provider invariantName = "System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
		// 此项位于   <entityFramework> <providers> </providers></entityFramework> 中
		/*public void Test()
		{
			using (var context = new FyDbContext())
			{
				Entities.TProjectInfo projectInfo = new Entities.TProjectInfo { CreateTime = DateTime.Now, Name = "Project001", ProjectCode = "zbyy2024" };
				context.TProjectInfoDbSet.Add(projectInfo);

				Entities.TProjectInjectionInfo injectionInfo = new Entities.TProjectInjectionInfo { ProjectCode = projectInfo.ProjectCode, CreateTime = DateTime.Now, Fragment = "xxx", ShamMean = "this is int ", TruthfulMean = "this is b", HashCode = "ERYUHNJMKDCFGVHBJKGHJK++" };
				context.InjectionDbSet.Add(injectionInfo);
				context.SaveChanges();

				List<Entities.TProjectInfo> projectInfos = context.TProjectInfoDbSet.ToList();
				List<Entities.TProjectInjectionInfo> projectInjectionInfos = context.InjectionDbSet.ToList();
				Console.WriteLine();
			}
		}*/
	}
}
